<?php
namespace Extend\Controller;

/**
 * 客栈相关rpc接口
 * @modify trainyao 2016-06-06 创建
 */
class HotelController extends ParentController {
    protected function _initialize() {
        $this->validateUtil = new \Org\Util\Validate();
    }

    private $couponUseType = array(
        'zh_cn' => array(
            COUPON_NOT_RECEIPT => '领取',
            COUPON_RECEIPT => '已领取',
        ),
        'en_us' => array(
            COUPON_NOT_RECEIPT => 'Not receive',
            COUPON_RECEIPT => 'Received',
        ),
        'zh_tw' => array(
            COUPON_NOT_RECEIPT => '領取',
            COUPON_RECEIPT => '已領取',
        ),
    );

    private $userCouponType = array(
        'zh_cn' => array(
            USER_COUPON_NOT_USE => '去使用',
            USER_COUPON_USED => '已使用',
            USER_COUPON_CANCELED => '已失效',
            USER_COUPON_OUTDATED => '已过期',
        ),
        'en_us' => array(
            USER_COUPON_NOT_USE => 'Use',
            USER_COUPON_USED => 'Used',
            USER_COUPON_CANCELED => 'Invalid',
            USER_COUPON_OUTDATED => 'Expired',
        ),
        'zh_tw' => array(
            USER_COUPON_NOT_USE => '去使用',
            USER_COUPON_USED => '已使用',
            USER_COUPON_CANCELED => '已失效',
            USER_COUPON_OUTDATED => '已過期',
        ),
    );

    /**
     * 获取用户有效订单或历史订单
     * @modify trainyao 2016-06-06  创建
     * @param intetger $id 加密用户id
     */
    public function publicLink($data) {
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $validateRule = array(
            'id' => 'notnull,notempty',
        );
        $validatePass = $this->validateUtil->validate($data, $validateRule);
        if (empty($validatePass)) {
            $message = $this->validateUtil->getError('explode', ',');
            return parent::returnJson($message['msg'][0], $message['msg'][1]);
        }
        $hashIdsUtil = new \Org\Util\Hashids(C('HASHIDS_SALT'), 16);
        $id = $hashIdsUtil->decode($data['id']);
        $id = $id[0];
        $validatePass = $this->validateUtil->validate($id, 'id');
        if (empty($validatePass)) {
            $message = $this->validateUtil->getError('explode', ',');
            return parent::returnJson($message['msg'][0], $message['msg'][1]);
        }

        $returnData = array(
            'name' => '',
            'imageUrl' => '',
            'hotels' => array(),
        );
        // 取出公共推广链接信息
        $adminDetailModel = D('AdminDetail');
        $adminDetail = $adminDetailModel->getInfoByUser($id);
        if (!empty($adminDetail)) {
            $returnData['name'] = $adminDetail['name'];
            $returnData['imageUrl'] = MEIZHU_URL . $adminDetail['imageurl'];
        }

        // 取出已上架微预定客栈信息
        $hotelLogic = A('Common/Hotel', 'Logic');
        $hotelInfos = $hotelLogic->getHotelByUser($id);
        if (!empty($hotelInfos)) {
            $hotelInfos = getArrayValueAsIndex($hotelInfos, 'role', 'multi');
            $hotelInfos = $hotelInfos[HOTEL_ROLE_OWNER];
            if (!empty($hotelInfos)) {
                $hotelIds = array_unique(array_column($hotelInfos, 'hotelentity_id'));
                $hotelDetailModel = D('HotelDetail');
                $hotelDetails = $hotelDetailModel->getInfoByHotel($hotelIds);
                if (count($hotelIds) == 1) {
                    $hotelDetails = array($hotelDetails);
                }

                foreach ($hotelDetails as $hotelDetailItem) {
                    if ($hotelDetailItem['enable'] == ENABLE) {
                        array_push($returnData['hotels'], array(
                            'id' => $hotelDetailItem['hotelentity_id'],
                            'name' => $hotelDetailItem['name'],
                            'imageUrl' => MEIZHU_URL . $hotelDetailItem['coverimageurl'],
                        ));
                    }
                }
                unset($hotelDetailItem);
            }
        }

        return parent::returnJson(200, 200, $returnData);
    }

    /**
     * 获取客栈预定端信息
     * @modify trainyao 2016-05-03    创建
     */
    public function info($data) {
        parent::switchTimeUtc($data);
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
        );
        $validatePass = $this->validateUtil->validate($data, $validateRule);
        if (empty($validatePass)) {
            $message = $this->validateUtil->getError('explode', ',');
            return parent::returnJson($message['msg'][0], $message['msg'][1]);
        }

        // 检查客栈是否已经开通微预定
        $hotelId = $data['hotel'];
        $bookLangSet = isset($data['bookLangSet']) ? $data['bookLangSet'] : LANG_SET;
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId, false);
        if (empty($isEnable)) {
            return parent::returnJson(403, 409);
        }

        // 获取客栈预定端信息,处理返回
        $hotelDetail = $hotelBookLogic->getInfo($hotelId, false, $bookLangSet);
        foreach ($hotelDetail['facility'] as $index => $facilityItem) {
            if ($facilityItem['enable'] == DISABLE) {
                unset($hotelDetail['facility'][$index]);
            }
        }
        unset($facilityItem);
        foreach ($hotelDetail['specialTag'] as $index => $tagItem) {
            if ($tagItem['enable'] == DISABLE) {
                unset($hotelDetail['specialTag'][$index]);
            }
        }
        unset($tagItem);
        foreach ($hotelDetail['gallery'] as &$urlItem) {
            $urlItem = MEIZHU_URL . $urlItem['name'];
        }
        unset($urlItem);

        $hourRoomInitModel = D('HourRoomInit');
        $hourRoom = $hourRoomInitModel->getInfo($hotelId);
        $roomTypeModel = D('RoomType');
        $longRoom = $roomTypeModel->where(['hotelentity_id'=>$hotelId,'longprice'=>['NEQ',0.00]])->find();
        // 只获取hotelspecial表的special，specialImageUrl字段
        $hotelSpecial = $hotelBookLogic->getSpecial($hotelId);

        // 获取客栈货币默认符号
        $currencyLogic = A('Common/Currency', 'Logic');
        $hotelCurrency = $currencyLogic->takeHotelCurrency($hotelId, false, $bookLangSet);
        if (!empty($hotelCurrency)) {
            $hotelCurrency = my_sort($hotelCurrency, 'type', SORT_DESC);
            // 是否有默认货币
            if ($hotelCurrency[0]['type'] == 1) {
                $defaultCurrency = $hotelCurrency[0];
                unset($defaultCurrency['hotelCurrencyId']);
                unset($defaultCurrency['currencyId']);
                unset($defaultCurrency['standSymbol']);
                unset($defaultCurrency['type']);
            } else {
                $bpCurrency = $currencyLogic->getBpCurrency();
                $bpCurrency = getArrayValueAsIndex($bpCurrency, 'id');
                $defaultCurrency = array(
                    'name' => $bpCurrency[8]['name'] . ' (' . $bpCurrency[8]['symbol'] . ')',
                    'symbol' => $bpCurrency[8]['symbol'],
                );
            }
        } else {
            $defaultCurrency = '';
        }

        return parent::returnJson(200, 200, array(
            'hotel' => $hotelId,
            'hotelName' => $hotelDetail['name'],
            'longtitude' => $hotelDetail['longtitude'],
            'latitude' => $hotelDetail['latitude'],
            'coverImageUrl' => MEIZHU_URL . $hotelDetail['coverimageurl'],
            'areaCode' => $hotelDetail['areacode'],
            'mobile' => $hotelDetail['mobile'],
            'telephone' => $hotelDetail['telephone'],
            'wechat' => $hotelDetail['wechat'],
            'hotline' => $hotelDetail['hotline'],
            'contact' => $hotelDetail['contact'],
            'address' => $hotelDetail['address'],
            'description' => $hotelDetail['description'],
            'facility' => array_column($hotelDetail['facility'], 'name'),
            'special' => $hotelSpecial['special'],
            'specialImageUrl' => MEIZHU_URL . $hotelSpecial['specialimageurl'],
            'logoImageUrl' => MEIZHU_URL . $hotelDetail['logoimageurl'],
            'specialTag' => array_column($hotelDetail['specialTag'], 'name'),
            'gallery' => array_values($hotelDetail['gallery']),
            'hourroom' => $hourRoom,
            'longroom' => $longRoom,
            'hotelIcon' => $hotelDetail['hotelIcon'],
            'defaultCurrency' => $defaultCurrency,
        ));
    }

    /**
     * 获取客栈支付信息
     * @modify trainyao 2016-05-03    创建
     */
    public function payInfo($data) {
        parent::switchTimeUtc($data);
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $validateRule = array(
            'hotel' => 'notnull,notempty,id',
        );
        $validatePass = $this->validateUtil->validate($data, $validateRule);
        if (empty($validatePass)) {
            $message = $this->validateUtil->getError('explode', ',');
            return parent::returnJson($message['msg'][0], $message['msg'][1]);
        }

        // 检查客栈是否已经开通微预定
        $hotelId = $data['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        $isEnable = $hotelBookLogic->checkEnable($hotelId, false);
        if (empty($isEnable)) {
            return parent::returnJson(403, 409);
        }

        // 获取客栈预定端支付信息,处理返回
        $hotelPayLogic = A('Common/HotelPay', 'Logic');
        $hotelPayInfo = $hotelPayLogic->getPartnerPayInfo($hotelId);

        return parent::returnJson(200, 200, array(
            'type' => $hotelPayInfo['type'],
            'partnerPayInfo'=> array(
                'wechat' => array(
                    'appid' => $hotelPayInfo['partnerPayInfo']['wechat']['appid'],
                    'appsecret' => $hotelPayInfo['partnerPayInfo']['wechat']['appsecret'],
                    'mchid' => $hotelPayInfo['partnerPayInfo']['wechat']['mchid'],
                    'mchkey' => $hotelPayInfo['partnerPayInfo']['wechat']['mchkey'],
                ),
                'ali' => array(
                    'account' => $hotelPayInfo['partnerPayInfo']['ali']['account'],
                    'pid' => $hotelPayInfo['partnerPayInfo']['ali']['pid'],
                    'key' => $hotelPayInfo['partnerPayInfo']['ali']['key'],
                ),
            ),
        ));
    }

    /**
     * 获取附近客栈
     * @modify wenhui 2016-12-28    创建
     * @modify wenhui 2017-02-22 返回市所在省的客栈 v1.0.02版本判断
     */
    public function getHotelNear($data) {
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $validateRule = array(
            'longtitude' => 'notempty,decimal9_6',
            'latitude' => 'notempty,decimal9_6',
            'version' => 'notempty,notnull',
        );
        $validatePass = $this->validateUtil->validate($data, $validateRule);
       if (empty($validatePass)) {
            $message = $this->validateUtil->getError('explode', ',');
            return parent::returnJson($message['msg'][0], $message['msg'][1]);
        }

        $pageSize = $data['pageSize'];
        $pageIndex = $data['pageIndex'];
        $city = $data['city'];
        $longtitude = $data['longtitude'];
        $latitude = $data['latitude'];
        $version = $data['version'];

        // 获取附近客栈信息,处理返回
        $HotelFindLogic = A('Common/HotelFind', 'Logic');
        if (!is_null($city) && !empty($city) && !empty($longtitude) && !empty($latitude)) {
            $hotelAllInfo = $HotelFindLogic->getHotelNear($city, $longtitude, $latitude, $pageSize, $pageIndex, $version);
            if (!$hotelAllInfo) {
                return parent::returnJson(403);
            }

            return parent::returnJson(200, 200, $hotelAllInfo);
        }else{
            $hotelAllInfo = $HotelFindLogic->getHotelNear(null, null, null, $pageSize, $pageIndex, $version);
            if (!$hotelAllInfo) {
                return parent::returnJson(403);
            }

            return parent::returnJson(200, 200, $hotelAllInfo);
        }

    }

     /**
     * 实时搜索客栈
     * @modify wenhui 2016-12-28    创建
     */
    public function searchHotel($data) {
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $keyWord = $data['keyWord'];
        $city = $data['city'];

        // 获取附近客栈信息,处理返回
        $HotelFindLogic = A('Common/HotelFind', 'Logic');
        if (is_null($city) && is_null($keyWord)) {
            // 获取热门客栈
            $hotelAllInfo = $HotelFindLogic->searchHotel(null, null);
            return parent::returnJson(200, 200, $hotelAllInfo);
        }

        if (!is_null($city) && !empty($city)) {
            $hotelAllInfo = $HotelFindLogic->searchHotel($city, $keyWord);

            return parent::returnJson(200, 200, $hotelAllInfo);
        } else {
            $hotelAllInfo = $HotelFindLogic->searchHotel(null, $keyWord);

            return parent::returnJson(200, 200, $hotelAllInfo);
        }
    }

    /**
     * 订客栈 搜索符合条件数据
     * @modify wenhui 2017-01-05    创建
     * @modify wenhui 2017-02-22 返回市所在省的客栈 v1.0.02版本判断
     */
    public function bookHotel($data) {
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $validateRule = array(
            'longtitude' => 'notempty,decimal9_6',
            'latitude' => 'notempty,decimal9_6',
            'startDate' => 'notempty,notnull',
            'endDate' => 'notempty,notnull',
            'version' => 'notempty,notnull',
        );
        $validatePass = $this->validateUtil->validate($data, $validateRule);
        if (empty($validatePass)) {
            $message = $this->validateUtil->getError('explode', ',');
            return parent::returnJson($message['msg'][0], $message['msg'][1]);
        }

        $pageSize = $data['pageSize'];
        $pageIndex = $data['pageIndex'];
        $sortType = $data['sortType'];
        $city = $data['city'];
        $longtitude = $data['longtitude'];
        $latitude = $data['latitude'];
        $endDate = $data['endDate'];
        $startDate = $data['startDate'];
        $version = $data['version'];
        $langSet = $data['langSet'];

        // 存放客栈信息
        $hotelRoomInfo = array();
        // 存放美住线上测试客栈  并排序到最后
        $testHotel = array();

        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $HotelFindLogic = A('Common/HotelFind', 'Logic');
        $hotelBookLogic = A('Common/HotelBook', 'Logic');

        // 获取客栈信息
        $hotelAllInfo = $HotelFindLogic->bookHotel($city, $longtitude, $latitude, $version, $startDate, $endDate, $langSet);
        $hotelEntity = $hotelAllInfo['hotelEntity'];
        $hotelAllInfo = $hotelAllInfo['hotelInfo'];
        if (empty($hotelAllInfo)) {
            return parent::returnJson(403);
        }

        // 根据客栈id 查新所有房型实时房态
        foreach ($hotelAllInfo as $key => $hotelAllList) {
            // 过滤没有名称的酒店
            if (empty($hotelAllList['name'])) {
                unset($hotelAllInfo[$key]);
                continue;
            }

            if ($version >= '1.0.04') {
                // 获取客栈预定端信息,处理返回
                $hotelDetail = $hotelBookLogic->getInfo($hotelAllList['hotelentity_id']);
            }

            // 获取客栈所有房型实时房态
            try {
                $roomTypeInfo = $roomTypeBookLogic->getRealtimeStatus($hotelAllList['hotelentity_id'], $startDate, $endDate);
            } catch (\Exception $e) {
                $errorMsg = explode(',', $e->getMessage());
                return parent::returnJson($errorMsg[0], $errorMsg[1]);
            }

            if (!empty($roomTypeInfo)) {
                // 处理数据
                foreach ($roomTypeInfo as &$roomTypeItem) {
                    sort($roomTypeItem['priceList'], SORT_NUMERIC);
                    sort($roomTypeItem['shopPriceList'], SORT_NUMERIC);
                    $roomTypeItems = array(
                        'roomType' => $roomTypeItem['roomtype_id'],
                        'roomName' => $roomTypeItem['name'],
                        'rest' => $roomTypeItem['rest'],
                        'minusType' => $roomTypeItem['minustype'],
                        'price' => $roomTypeItem['priceList'][0],
                        'shopPrice' => isset($roomTypeItem['shopPriceList'][0]) ? $roomTypeItem['shopPriceList'][0] : '',
                        'hotel' => $roomTypeItem['hotelentity_id'],
                        'roomTypeCoverUrl' => (!isset($roomTypeItem['coverimageurl']) || $roomTypeItem['coverimageurl'] == '') ? '' : MEIZHU_URL . $roomTypeItem['coverimageurl'],
                        'hotelName' => $hotelAllList['name'],
                        'distance' => $hotelAllList['distance'],
                        'district' => $hotelAllList['district'],
                        'isRecommend' => $hotelAllList['isRecommend'],
                        'click' => $hotelAllList['click'],
                        'longtitude' => $hotelAllList['longtitude'],
                        'latitude' => $hotelAllList['latitude'],
                        'bookRoomUrl' => "http://" . MEIZHU_BOOK_HOST . "/Home/BookPage/room?hotel={$roomTypeItem['hotelentity_id']}&roomType={$roomTypeItem['roomtype_id']}&startDate={$startDate}&endDate={$endDate}",
                    );

                    if ($version >= '1.0.02') {
                        $roomTypeItems['description'] = $roomTypeItem['description'];
                        $roomTypeItems['bookHotelUrl'] = "http://" . MEIZHU_BOOK_HOST . "/Home/BookPage/index?hotel={$roomTypeItem['hotelentity_id']}";
                    }
                    if ($version >= '1.0.04') {
                        if (!empty($hotelDetail)) {
                            $roomTypeItems['hotelIcon'] = $hotelDetail['hotelIcon'];
                        } else {
                            $roomTypeItems['hotelIcon'] = array(
                                    'hotelIcon' => false, // 是否显示认证图标
                                    'hotelSafeguardIcon' => false, // 是否显示保障金图标
                                    'hotelCreditIcon' => false, // 是否显示诚信交易图标
                                    'hotelBrandIcon' => false, // 是否显示优质品牌客栈图标
                            );
                        }
                    }

                    // 取出测试客
                    if ($hotelEntity[$roomTypeItem['hotelentity_id']]['usage'] == 3) {
                        array_push($testHotel, $roomTypeItems);
                    } else {
                        array_push($hotelRoomInfo, $roomTypeItems);
                    }
                }
                unset($roomTypeItem);
            } else {
                unset($hotelAllInfo[$key]);
            }
        }
        unset($hotelAllList);

        if (empty($hotelRoomInfo) && empty($testHotel)) {
            return parent::returnJson(403);
        }
        // 如果是推荐的客栈房型 就按照排序方式 1：综合排序（按浏览量）
        if ($hotelRoomInfo[0]['isRecommend'] == 1 && $sortType == 2) {
            $sortType = ENABLE;
        }

        /**
         *  排序
         *  排序方式 1：综合排序（按浏览量） 2:离我最近（按距离） 3:价格最高 4:价格最低
         *  SORT_ASC - 默认，按升序排列。(A-Z)
         *  SORT_DESC - 按降序排列。(Z-A)
         *  随后可以指定排序的类型：
         *  SORT_REGULAR - 默认。将每一项按常规顺序排列。
         *  SORT_NUMERIC - 将每一项按数字顺序排列。
         *  SORT_STRING - 将每一项按字母顺序排列
         */
        switch ($sortType) {
          case 1:
            $hotelRoomInfo = my_sort($hotelRoomInfo, 'click', SORT_DESC, SORT_NUMERIC);
            break;
          case 2:
            usort($hotelRoomInfo, function($left, $right) {
              return $left['distance'] - $right['distance'];
            });
            break;
          case 3:
            $hotelRoomInfo = my_sort($hotelRoomInfo, 'price', SORT_DESC, SORT_NUMERIC);
            break;
          case 4:
            $hotelRoomInfo = my_sort($hotelRoomInfo, 'price', SORT_ASC, SORT_NUMERIC);
            break;
        }

        //美住线上测试客栈排序到最后
        $hotelRoomInfo = array_merge($hotelRoomInfo, $testHotel);
        $hotelRoomInfo = generatePageInfo($hotelRoomInfo, $pageIndex, $pageSize);
        $hotelRoomInfo['hotelCount'] = count($hotelAllInfo);

        return parent::returnJson(200, 200, $hotelRoomInfo);
    }

    /**
     * 获取全部客栈的掌柜说信息
     * @modify wenhui 2017-01-06    创建
     * @modify wenhui 2017-02-27 增加版本判断
     * @modify wenhui 2017-02-22 返回市所在省的客栈 v1.0.02版本判断
     */
    public function getManagerInfo($data) {
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $validateRule = array(
            'longtitude' => 'notempty,decimal9_6',
            'latitude' => 'notempty,decimal9_6',
        );
        $validatePass = $this->validateUtil->validate($data, $validateRule);
        if (empty($validatePass)) {
            $message = $this->validateUtil->getError('explode', ',');
            return parent::returnJson($message['msg'][0], $message['msg'][1]);
        }

        $version = $data['version'];
        $pageSize = $data['pageSize'];
        $pageIndex = $data['pageIndex'];
        $city = $data['city'];
        $longtitude = $data['longtitude'];
        $latitude = $data['latitude'];

        $HotelFindLogic = A('Common/HotelFind', 'Logic');
        // 根据城市市区 获取所有客栈掌柜说信息
        $hotelAllManager = $HotelFindLogic->getManagerInfo($city, $longtitude, $latitude, $pageIndex, $pageSize, $version);

        if (empty($hotelAllManager)) {
            return parent::returnJson(403);
        }

        return parent::returnJson(200, 200, $hotelAllManager);
    }

    /**
     * 获取单个客栈所有掌柜说信息
     * @modify wenhui 2017-01-06    创建
     * @modify wenhui 2017-02-27 增加版本判断
     */
    public function getHotelManager($data) {
        parent::switchTimeUtc($data);
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $version = $data['version'];
        $hotel = $data['hotel'];
        $version = $data['version'];
        $HotelFindLogic = A('Common/HotelFind', 'Logic');
        // 根据城市市区 获取所有客栈掌柜说信息
        $hotelAllManager = $HotelFindLogic->getInfoByHotel($hotel, $version);

        // v1.0.02 添加客栈最低价
        if ($version >= '1.0.02') {
            // 获取客栈最低价
            $hotelRoomInfo = getHoteRoomTypePrice($hotel);
            if (isset($hotelRoomInfo['minPrice'])) {
                $hotelAllManager['minPrice'] = $hotelRoomInfo['minPrice'];
            }
        }

        return parent::returnJson(200, 200, $hotelAllManager);
    }

    /**
     * 获取优选品牌
     * @modify wenhui 2017-01-06    创建
     */
    public function getBrandInfo($data) {
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $validateRule = array(
            'longtitude' => 'notempty,decimal9_6',
            'latitude' => 'notempty,decimal9_6',
        );
        $validatePass = $this->validateUtil->validate($data, $validateRule);
        if (empty($validatePass)) {
            $message = $this->validateUtil->getError('explode', ',');
            return parent::returnJson($message['msg'][0], $message['msg'][1]);
        }

        $pageSize = $data['pageSize'];
        $pageIndex = $data['pageIndex'];
        $city = $data['city'];
        $longtitude = $data['longtitude'];
        $latitude = $data['latitude'];
        $version = $data['version'];
        $langSet = $data['langSet'];

        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        $HotelFindLogic = A('Common/HotelFind', 'Logic');
        // 获取客栈信息
        $hotelAllInfo = $HotelFindLogic->getBrandInfo($city, $longtitude, $latitude, $pageIndex, $pageSize, $version, $langSet);

        if (empty($hotelAllInfo)) {
            return parent::returnJson(403);
        }

        if ($version >= '1.0.04' && !empty($hotelAllInfo['hotelInfo'])) {
            $hotelBookLogic = A('Common/HotelBook', 'Logic');
            // 获取客栈预定端信息,处理返回
            foreach ($hotelAllInfo['hotelInfo'] as $key => &$hotels) {
                $hotelDetail = $hotelBookLogic->getInfo($hotels['hotel']);
                if (!empty($hotelDetail)) {
                    $hotels['hotelIcon'] = $hotelDetail['hotelIcon'];
                } else {
                    $hotels['hotelIcon'] = array(
                            'hotelIcon' => false, // 是否显示认证图标
                            'hotelSafeguardIcon' => false, // 是否显示保障金图标
                            'hotelCreditIcon' => false, // 是否显示诚信交易图标
                            'hotelBrandIcon' => false, // 是否显示优质品牌客栈图标
                    );
                }
            }
            unset($hotels);
        }

        return parent::returnJson(200, 200, $hotelAllInfo);
    }

    /**
     * 获取优选品牌
     * @modify wenhui 2017-01-06    创建
     */
    public function rememberClick($data) {
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $hotel = $data['hotel'];
        $HotelFindLogic = A('Common/HotelFind', 'Logic');
        $hotelResult = $HotelFindLogic->rememberClick($hotel);

        return parent::returnJson(200, 200);
    }

    /**
     * 分享我的客栈链接
     * @modify wenhui 2017-02-24    创建
     */
    public function hotelShareLink($data) {
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }
        $hotelId = $data['hotel'];
        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        // 以选中的客栈标签 作为分享描述
        $hotelDetail = $hotelBookLogic->getInfo($hotelId);
        $description = '';
        foreach ($hotelDetail['specialTag'] as $specialTags) {
            if ($specialTags['enable'] == ENABLE) {
                $description .= $specialTags['name'] . ' ';
            }
        }
        unset($specialTags);

        $hotel = $param['hotel'];
        $hotelName = $hotelDetail['name'];
        $description = trim($description);
        $imageUrl = isset($hotelDetail['logoimageurl']) && !empty($hotelDetail['logoimageurl']) ? MEIZHU_URL . $hotelDetail['logoimageurl'] : '';
        return parent::returnJson(200, 200, array(
            'link' => 'http://' . MEIZHU_BOOK_HOST . '/Home/BookPage/index?hotel=' . $hotelId,
            'hotelName' => $hotelName,
            'description' => $description,
            'defaultUrl' => MEIZHU_URL . '/Public/uclbrt/image/qrclient.png',
            'imageUrl' => $imageUrl,
        ));
    }

    /**
     * 获取客栈所有房型价格
     * @modify wenhui 2017-02-21    创建
     */
    public function getHotelPrice($data) {
        parent::switchTimeUtc($data);
        $hotelId = $data['hotelId'];
        $roomTypeDetailModel = D('RoomTypeDetail');
        $hotelRoomTypePriceModel = D('HotelRoomTypePrice');
        $roomTypePriceModel = D('RoomTypePrice');
        $roomTypeModel = D('RoomType');
        // 根据客栈id获取所有房型id
        // 获取客栈所有上架房型
        $roomTypeDetail = $roomTypeDetailModel->getInfoByHotel($hotelId, true);
        /*$roomTypeId = array_column($roomTypeDetail, 'roomtype_id');
        // 根据客栈id 获取每个客栈房间总数
        if (!empty($roomTypeDetail)) {
            $roomInfo = $roomInfoModel->getInfoByRoomType($hotelList['hotelentity_id'], $roomTypeId);
            $hotelList['roomTotal'] = count($roomInfo);
        } else {
            $hotelList['roomTotal'] = 0;
        }*/

        // 获取客栈房型当天价格日历的价格
        if (!empty($roomTypeDetail)) {
            foreach ($roomTypeDetail as $index => &$roomTypeDetailItem) {
                // 房型折扣值
                $roomTypeDiscountInfo = $roomTypeModel->getInfo($roomTypeDetailItem['roomtype_id']);
                $discount = ($roomTypeDiscountInfo['discount'])/10;

                // 获取预定价格
                $hotelRoomTypePriceList = $hotelRoomTypePriceModel->getBookPrice($roomTypeDetailItem['roomtype_id'], $startDate);
                $roomTypePriceList = $roomTypePriceModel->getBookPrice($roomTypeDetailItem['roomtype_id'], $startDate);
                if (!empty($hotelRoomTypePriceList)) {
                    $roomTypeDetailItem['price'] = number_format($hotelRoomTypePriceList[0]['price'],2, '.', '');
                } else {

                    if (!empty($roomTypePriceList)) {
                        $roomTypeDetailItem['price'] = number_format((($roomTypePriceList[0]['price']*1000)/1000) * $discount ,2, '.', '');
                    } else {
                        $roomTypeDetailItem['price'] = number_format((($roomTypeDiscountInfo['price']*1000)/1000) * $discount, 2, '.', '');
                    }
                }
            }
        }

        if (!empty($roomTypeDetail)) {
            // 获取客栈房型的最高价与最低价
            $roomTypeDetail = my_sort($roomTypeDetail, 'price', SORT_DESC, SORT_NUMERIC);
            $hotelList['maxPrice'] = $roomTypeDetail[0]['price'];
            $hotelList['minPrice'] = $roomTypeDetail[count($roomTypeDetail) - 1]['price'];
        }
        $hotelList = isset($hotelList) ? $hotelList : array();

        return parent::returnJson(200, 200, $hotelList);
    }
    /**
     * @description 获取广告
     * @modify zhangzhen 2017-4-10
     */
    public function hotelrest($data) {
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }
        $redisUtil = new \Redis();
        $redisUtil->connect(C('REDIS_SERVERIP'), C('REDIS_SERVERPORT'));
        $redisUtil->auth(C('REDIS_AUTH_PASSWORD'));
        $rest = $redisUtil->get('hotelrest');
        if (empty($rest)) {
            return parent::returnJson(200, 200, 0);
        } else {
            return parent::returnJson(200, 200, ['rest' => $rest,'url' => MEIZHU_URL.'/package.html']);
        }
    }

    /**
     * 获取区号时区数据
     * @modify wenhui 2017-06-16
     * @modify zhangzhen 2017-07-02
     * @return array $data 时区数据
     */
    public function bookUniversalTimeList($input) {
        $bookLangSet = isset($input['bookLangSet']) ? $input['bookLangSet'] : LANG_SET;
        //获取区号时区数据
        $HotelLogic = A('Common/Hotel', 'Logic');
        $universalTimeData = $HotelLogic->universalTimeList($bookLangSet);
        return $universalTimeData;
    }

    /**
     * 获取优惠券
     * @modify wenhui 2017-01-02    创建
     */
    public function getCoupon($data) {
        parent::switchTimeUtc($data);
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $validateRule = array(
            'hotelId' => 'notnull,notempty,id',
        );
        if (!is_null($data['userId'])) {
            $validateRule['userId'] = 'notnull,notempty,id';
        }

        $validatePass = $this->validateUtil->validate($data, $validateRule);
        if (empty($validatePass)) {
            $message = $this->validateUtil->getError('explode', ',');
            return parent::returnJson($message['msg'][0], $message['msg'][1]);
        }

        $hotelId = $data['hotelId'];
        $userId = $data['userId'];
        $bookLangSet = $data['bookLangSet'];
        $status = isset($data['status']) ? $data['status'] : null;

        // 微信登录 没有绑定手机号 即 USER_ID = 0  算没有登录
        $isLogin = !is_null($userId) && $userId != 0 ? true : false;
        $vipUser = false;
        $userCouponData = array();
        if ($isLogin) {
            $userCouponModel = D('UserCoupon');
            $userCouponData = $userCouponModel->getUserCoupon($userId);
            $userCouponData = getArrayValueAsIndex($userCouponData, 'coupon_id', true);

            $userLoginModel = D('UserLogin');
            $vipUserModel = D('VipUser');
            $userLoginInfo = $userLoginModel->getInfo($userId);
            $vipUserInfo = $vipUserModel->getInfoByMobile($hotelId, $userLoginInfo['mobile'], $userLoginInfo['areacode']);
            // 是否是会员
            if (!empty($vipUserInfo)) {
                $vipUser = true;
            }
        }

        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        // 校验是否已经开通
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            return parent::returnJson(403, 410);
        }

        // 获取客栈优惠券
        $hotelCouponData = $hotelBookLogic->getCoupon($hotelId);

        // 处理数据
        foreach ($hotelCouponData as $key => &$hotelCoupon) {
            // 过滤已过期
            if (date('Y-m-d', strtotime($hotelCoupon['couponEnd'])) < date('Y-m-d')) {
                unset($hotelCouponData[$key]);
                continue;
            }
            // 登录
            if ($isLogin) {
                if ($vipUser) {
                    // 会员 返回全部和会员优惠券
                    if (!in_array($hotelCoupon['couponUseMan'], [COUPON_ALL_USER,COUPON_VIP_USER])) {
                        unset($hotelCouponData[$key]);
                        continue;
                    }
                } else {
                    // 非会员 返回全部和非会员优惠券
                    if (!in_array($hotelCoupon['couponUseMan'], [COUPON_ALL_USER,COUPON_NOT_VIP_USER])) {
                        unset($hotelCouponData[$key]);
                        continue;
                    }
                }
            } else {
                // 没登录返回全部使用的优惠券
                if (!in_array($hotelCoupon['couponUseMan'], [COUPON_ALL_USER])) {
                    unset($hotelCouponData[$key]);
                    continue;
                }
            }

            // 优惠券总数量 与 所有用户已领取数量 比较 （couponNumber = 0 无限制 ）
            if ($hotelCoupon['couponNumber'] != 0 && $hotelCoupon['getCouponNumber'] >= $hotelCoupon['couponNumber']) {
                unset($hotelCouponData[$key]);
                continue;
            }

            if (empty($userCouponData)) {
                $hotelCoupon['receiveType'] = $this->couponUseType[$bookLangSet][COUPON_NOT_RECEIPT];
                $hotelCoupon['status'] = COUPON_NOT_RECEIPT;
            } else {
                // 优惠券每个用户可领取次数 与 该用户已领取的次数 比较
                if (count($userCouponData[$hotelCoupon['couponId']]) >= $hotelCoupon['couponReceiveTotal']) {
                    $hotelCoupon['receiveType'] = $this->couponUseType[$bookLangSet][COUPON_RECEIPT];
                    $hotelCoupon['status'] = COUPON_RECEIPT;
                } else {
                    $hotelCoupon['receiveType'] = $this->couponUseType[$bookLangSet][COUPON_NOT_RECEIPT];
                    $hotelCoupon['status'] = COUPON_NOT_RECEIPT;
                }
            }

            // status 过滤
            if (!is_null($status)) {
                if (!in_array($hotelCoupon['status'], [$status])) {
                    unset($hotelCouponData[$key]);
                    continue;
                }
            }

            $hotelCoupon['createtime'] = strtotime($hotelCoupon['createtime']);
        }
        unset($hotelCoupon);
        $hotelCouponData = array_values($hotelCouponData);

        return parent::returnJson(200, 200, $hotelCouponData);
    }

    /**
     * 获取优惠券详情
     * @modify wenhui 2017-01-02    创建
     */
    public function couponDetails($data) {
        parent::switchTimeUtc($data);
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $validateRule = array(
            'hotelId' => 'notnull,notempty,id',
            'couponNo' => 'notnull,notempty,cpOrder',
        );

        $validatePass = $this->validateUtil->validate($data, $validateRule);
        if (empty($validatePass)) {
            $message = $this->validateUtil->getError('explode', ',');
            return parent::returnJson($message['msg'][0], $message['msg'][1]);
        }

        $hotelId = $data['hotelId'];
        $couponId = decodeCouponNumber($data['couponNo'], 'CP');

        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        // 校验是否已经开通
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            return parent::returnJson(403, 410);
        }

        $hotelDetailModel = D('HotelDetail');
        $hotelCouponModel = D('HotelCoupon');
        $hotelCouponRoomTypeModel = D('HotelCouponRoomType');
        $hotelCouponDisableDateModel = D('HotelCouponDisableDate');

        $couponData = $hotelCouponModel->getCouponByIds($couponId);

        $couponRoomTypeData = $hotelCouponRoomTypeModel->getCouponRoomType($couponId);
        $couponRoomTypeData = getArrayValueAsIndex($couponRoomTypeData, 'roomtype_id');

        $couponDisableDate = $hotelCouponDisableDateModel->getCouponDisableDate($couponId);
        $couponDisableDate = getArrayValueAsIndex($couponDisableDate, 'coupon_id', true);

        $startDate = date('Y-m-d');
        $endDate = date('Y-m-d', strtotime('+1 day'));
        // 获取客栈所有房型实时房态
        $roomTypeBookLogic = A('Common/RoomTypeBook', 'Logic');
        try {
            $roomTypeInfo = $roomTypeBookLogic->getRealtimeStatus($hotelId, $startDate, $endDate);
        } catch (\Exception $e) {
            $errorMsg = explode(',', $e->getMessage());
            return parent::returnJson($errorMsg[0], $errorMsg[1]);
        }

        $roomTypeInfos = array();
        // 处理数据
        foreach ($roomTypeInfo as $roomTypeItem) {
            if (isset($couponRoomTypeData[$roomTypeItem['roomtype_id']])) {
                sort($roomTypeItem['priceList'], SORT_NUMERIC);
                sort($roomTypeItem['shopPriceList'], SORT_NUMERIC);
                // 如果预定价格等于门市价格 则只取预定价格
                $shopPrice = $roomTypeItem['priceList'][0] == $roomTypeItem['shopPriceList'][0] ? '' : $roomTypeItem['shopPriceList'][0];
                $roomTypeDetail = array(
                    'id' => $roomTypeItem['roomtype_id'],
                    'coverImageUrl' => MEIZHU_URL . $roomTypeItem['coverimageurl'],
                    'name' => $roomTypeItem['name'],
                    'price' => $roomTypeItem['priceList'][0],
                    'shopPrice' => $shopPrice,
                    'rest' => $roomTypeItem['rest'],
                    'description' => $roomTypeItem['description'],
                    'lastRoom' => $roomTypeItem['lastRoom'] ? true : false,
                    'minustype' => $roomTypeItem['minustype'],
                );

                array_push($roomTypeInfos, $roomTypeDetail);
            }
            
        }
        unset($roomTypeItem);

        // 处理数据
        $data = array();
        foreach ($couponData as $key => $coupon) {
            $week = !empty($coupon['week']) ? explode(',', $coupon['week']) : [];
            $hotelDetail = $hotelDetailModel->getInfoByHotel($coupon['hotelentity_id']);
            $couponDate = isset($couponDisableDate[$coupon['id']]) ? $couponDisableDate[$coupon['id']] : array();
            if (!empty($couponDate)) {
                foreach ($couponDate as &$date) {
                    $date['date'] = date('Y-m-d', $date['date']);
                }
                unset($date);
                $couponDate = array_column($couponDate, 'date');
                sort($couponDate);
            }
            $data = array(
                'couponId' => $coupon['id'],
                'couponName' => $coupon['name'],
                'couponNo' => $coupon['no'],
                'couponType' => $coupon['type'],
                'couponPrice' => (float)$coupon['price'],
                'couponDiscount' => (float)$coupon['discount'],
                'couponNumber' => $coupon['number'],
                'couponStart' => date('Y/m/d', strtotime($coupon['startdate'])),
                'couponEnd' => date('Y/m/d', strtotime($coupon['enddate'])),
                'couponWeek' => $week,
                'couponUseMan' => $coupon['crowd'],
                'couponRoomType' => $coupon['roomtype'],
                'couponMinusPrice' => (float)$coupon['minus_price'],
                'couponReceiveTotal' => $coupon['receive_number'],
                'hotelName' => $hotelDetail['name'],
                'bookmode' => $hotelDetail['bookmode'],
                'couponDate' => $couponDate,
                'roomTypeInfos' => $roomTypeInfos,
            );
        }
        unset($coupon);

        return parent::returnJson(200, 200, $data);
    }

    /**
     * 领取用户优惠券
     * @modify wenhui 2017-01-02    创建
     */
    public function addUserCoupons($data) {
        parent::switchTimeUtc($data);
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $validateRule = array(
            'hotelId' => 'notnull,notempty,id',
            'userId' => 'notnull,notempty,id',
            'couponNo' => 'notnull,notempty,cpOrder',
        );

        $validatePass = $this->validateUtil->validate($data, $validateRule);
        if (empty($validatePass)) {
            $message = $this->validateUtil->getError('explode', ',');
            return parent::returnJson($message['msg'][0], $message['msg'][1]);
        }

        $hotelId = $data['hotelId'];
        $userId = $data['userId'];
        $couponId = decodeCouponNumber($data['couponNo'], 'CP');

        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        // 校验是否已经开通
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            return parent::returnJson(403, 410);
        }

        $userCouponModel = D('UserCoupon');
        $userCouponData = $userCouponModel->getUserCoupon($userId, $couponId);
        // 该优惠券该用户领取几张
        $userCouponTotal = count($userCouponData);

        // 该优惠券总共领取几张
        $couponTotal = $userCouponModel->getCouponTotal($couponId);

        $hotelCouponModel = D('HotelCoupon');
        $hotelCouponDisableDateModel = D('HotelCouponDisableDate');
        // 获取客栈优惠券信息
        $hotelCouponData = $hotelCouponModel->getCouponByIds($couponId);

        // 用户领取的优惠券是否达到上限
        if ($userCouponTotal >= $hotelCouponData[0]['receive_number']) {
            return parent::returnJson(403, 1000);
        }

        // 客栈的优惠券是否领取完
        if ($hotelCouponData[0]['number'] != 0 && $couponTotal[0]['coupontotal'] >= $hotelCouponData[0]['number']) {
            return parent::returnJson(403, 1001);
        }

        $hotelCouponModel->startTrans();
        $commit = true;

        $id = $addResult = $userCouponModel->addUserCoupons($userId, $couponId, $hotelId);
        if (empty($addResult)) {
            $commit = false;
        }

        // 生成领取码
        $getNo = encodeCouponNumber($id, 'UCP');
        if ($commit) {
            $saveResult = $userCouponModel->saveUserGetNo($id, $getNo);
            if ($saveResult === false) {
                $commit = false;
            }
        }

        //事务提交回滚
        if ($commit) {
            $hotelCouponModel->commit();
            return parent::returnJson(200, 200);
        } else {
            $hotelCouponModel->rollback();
            return parent::returnJson(500, 508);
        }
    }

    /**
     * 获取用户优惠券
     * @modify wenhui 2017-01-02    创建
     */
    public function getUserCoupons($data) {
        parent::switchTimeUtc($data);
        if (empty(parent::checkRPCRight($data))) {
            return parent::returnJson(403, 202);
        }

        $validateRule = array(
            'hotelId' => 'notnull,notempty,id',
            'userId' => 'notnull,notempty,id',
            'type' => 'notnull,notempty,id',
        );

        $validatePass = $this->validateUtil->validate($data, $validateRule);
        if (empty($validatePass)) {
            $message = $this->validateUtil->getError('explode', ',');
            return parent::returnJson($message['msg'][0], $message['msg'][1]);
        }

        $hotelId = $data['hotelId'];
        $userId = $data['userId'];
        $type = $data['type'];
        $bookLangSet = $data['bookLangSet'];

        $userCouponModel = D('UserCoupon');
        $userCouponData = $userCouponModel->getUserCoupon($userId);
        if (empty($userCouponData)) {
            return parent::returnJson(200, 200, array());
        }

        $couponIds = array_column($userCouponData, 'coupon_id');

        $hotelBookLogic = A('Common/HotelBook', 'Logic');
        // 校验是否已经开通
        $isEnable = $hotelBookLogic->checkEnable($hotelId);
        if (!$isEnable) {
            return parent::returnJson(403, 410);
        }

        $hotelEntityModel = D('HotelEntity');
        $hotelCouponModel = D('HotelCoupon');
        $hotelCouponRoomTypeModel = D('HotelCouponRoomType');
        $hotelCouponDisableDateModel = D('HotelCouponDisableDate');
        $orderRoomModel = D('OrderRoom');

        // 获取客栈优惠券信息
        $hotelCouponData = $hotelCouponModel->getCouponByIds($couponIds, true);
        $hotelCouponData = getArrayValueAsIndex($hotelCouponData, 'id');

        $couponRoomTypeData = $hotelCouponRoomTypeModel->getCouponRoomType($couponIds);
        $couponRoomTypeData = getArrayValueAsIndex($couponRoomTypeData, 'coupon_id', true);

        $couponDisableDate = $hotelCouponDisableDateModel->getCouponDisableDate($couponIds);
        $couponDisableDate = getArrayValueAsIndex($couponDisableDate, 'coupon_id', true);
        foreach ($couponDisableDate as $couponId => &$couponDisableDateItem) {
            foreach ($couponDisableDateItem as $key => &$couponDisable) {
                unset($couponDisable['id']);
                $couponDisable['date'] = date('Y-m-d', $couponDisable['date']);
            }
            unset($couponDisable);
        }
        unset($couponDisableDateItem);

        $vipUser = false;
        $userLoginModel = D('UserLogin');
        $vipUserModel = D('VipUser');
        $userLoginInfo = $userLoginModel->getInfo($userId);
        $vipUserInfo = $vipUserModel->getInfoByMobile($hotelId, $userLoginInfo['mobile'], $userLoginInfo['areacode']);
        // 是否是会员
        if (!empty($vipUserInfo)) {
            $vipUser = true;
        }

        // 处理数据
        $returnData = array();
        foreach ($userCouponData as $key => $userCoupon) {
            if ($vipUser) {
                // 会员 返回全部和会员优惠券
                if (!in_array($hotelCouponData[$userCoupon['coupon_id']]['crowd'], [COUPON_ALL_USER, COUPON_VIP_USER])) {
                    continue;
                }
            } else {
                // 非会员  返回全部和非会员优惠券
                if (!in_array($hotelCouponData[$userCoupon['coupon_id']]['crowd'], [COUPON_ALL_USER, COUPON_NOT_VIP_USER])) {
                    continue;
                }
            }

            // 优惠券存在订单 并且优惠券已过期
            if ($userCoupon['orderinfo_id'] != 0 && in_array($userCoupon['type'], [USER_COUPON_OUTDATED])) {
                $orderRoom = $orderRoomModel->getInfoByOrder($userCoupon['orderinfo_id'], false);
                $isUserCouponUsed = false;
                foreach ($orderRoom as $key => $orderRoomItem) {
                    // 已过期有效订单 则优惠券改成已使用
                    if ($orderRoomItem['status'] == ORDER_OUTDATED) {
                        $redisOrderRecordInfo = $orderRoomModel->getInfoInRedisByHotelRoomOrderRoom($userCoupon['hotelentity_id'], null, $orderRoomItem['id']);
                        if (!empty($redisOrderRecordInfo)) {
                            $isUserCouponUsed = true;
                        }
                    }
                }
                unset($orderRoomItem);

                if ($isUserCouponUsed) {
                    $userCoupon['type'] = USER_COUPON_USED;
                }
            }

            // 把用户有效已过期的优惠券改成 去使用
            if ($userCoupon['type'] == USER_COUPON_OUTDATED) {
                $userCoupon['type'] = strtotime($hotelCouponData[$userCoupon['coupon_id']]['enddate']) >= strtotime(date('Y-m-d')) ? USER_COUPON_NOT_USE : USER_COUPON_OUTDATED;
            }

            if ($type == 1) {
                if (in_array($userCoupon['type'], [USER_COUPON_USED,USER_COUPON_CANCELED,USER_COUPON_OUTDATED])) {
                    continue;
                }
            } else if ($type == 2) {
                if (in_array($userCoupon['type'], [USER_COUPON_NOT_USE])) {
                    continue;
                }
            }
             // 不可用星期
            $week = !empty($hotelCouponData[$userCoupon['coupon_id']]['week']) ? explode(',', $hotelCouponData[$userCoupon['coupon_id']]['week']) : [];
            // 不可用日期
            $couponDate = isset($couponDisableDate[$userCoupon['coupon_id']]) ? $couponDisableDate[$userCoupon['coupon_id']] : array();
            // 不可用房型
            $couponRoomType = isset($couponRoomTypeData[$userCoupon['coupon_id']]) ? $couponRoomTypeData[$userCoupon['coupon_id']] : array();
            $data = array(
                'couponId' => $userCoupon['coupon_id'],
                'userGetNo' => $userCoupon['no'],
                'hotelId' => $hotelCouponData[$userCoupon['coupon_id']]['hotelentity_id'],
                'couponName' => $hotelCouponData[$userCoupon['coupon_id']]['name'],
                'couponNo' => $hotelCouponData[$userCoupon['coupon_id']]['no'],
                'couponType' => $hotelCouponData[$userCoupon['coupon_id']]['type'],
                'couponPrice' => (float)$hotelCouponData[$userCoupon['coupon_id']]['price'],
                'couponDiscount' => (float)$hotelCouponData[$userCoupon['coupon_id']]['discount'],
                'couponStart' => date('Y/m/d', strtotime($hotelCouponData[$userCoupon['coupon_id']]['startdate'])),
                'couponEnd' => date('Y/m/d',strtotime($hotelCouponData[$userCoupon['coupon_id']]['enddate'])),
                'couponWeek' => $week,
                'couponMinusPrice' => (float)$hotelCouponData[$userCoupon['coupon_id']]['minus_price'],
                'userCouponType' => $this->userCouponType[$bookLangSet][$userCoupon['type']],
                'couponRoomType' => $couponRoomType,
                'couponDate' => $couponDate,
            );

            array_push($returnData, $data);
        }

        return parent::returnJson(200, 200, $returnData);
    }
}